<template>
  <div>
    <p style="font-size: 15px;line-height: 60px">修改密码</p>
    <el-row>
      <el-col :span=7></el-col>
      <el-col :span=8>
        <el-form :model="form" label-width="120px">
          <el-form-item label="账户">
            <el-input v-model="form.id"/>
          </el-form-item>
          <el-form-item label="旧密码">
            <el-input v-model="form.password" type="password"/>
          </el-form-item>
          <el-form-item label="新密码">
            <el-input v-model="form.new" type="password"/>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span=9></el-col>
    </el-row>
    <el-row></el-row>
    <p></p>
    <el-button type="primary" @click="onSubmit">修改</el-button>
  </div>
</template>

<script>

import axios from 'axios';
import Global from './Global.vue';

export default {
  name: 'ChangePwd',
  data() {
    return {
      form: {
        id: '',
        password: '',
        new: '',
      },
    };
  },
  methods: {
    onSubmit() {
      const path = '/api/password';
      if (this.form.id !== '' && this.form.password !== '' && this.form.new !== '' && this.form.id === Global.id) {
        axios.post(path, this.form)
          .then((res) => {
            if (res.data.ok) {
              this.$message.success('修改成功');
            } else {
              this.$message.success('修改失败');
            }
          })
          .catch((error) => {
            // eslint-disable-next-line
            console.error(error);
          });
      } else {
        this.$message.warning('账号或密码错误');
      }
    },
  },
};
</script>

<style scoped>

</style>
